package ch8recursion;

import java.util.LinkedHashSet;

public class Ex5 {

	public static LinkedHashSet<String> parenthesesR(int n) {
		LinkedHashSet<String> result = new LinkedHashSet<String>();
		if (n < 1) {
			return result;
		}
		else if (n == 1) {
			result.add("()");
			return result;
		}
		
		LinkedHashSet<String> subResult = parenthesesR(n-1);
		for (String str : subResult) {
			result.add("()"+str);
			result.add("("+str+")");
			result.add(str+"()");
		}
		return result;
	}
	
	public static void main(String ...strings) {
		LinkedHashSet<String> parenthesesR = parenthesesR(3);
		System.out.println(parenthesesR);
	}
}
